﻿package com.janisRadins.asDraw {
	import flash.display.GraphicsPath;
	import flash.geom.Point;
	/**
	 * @author Jānis Radiņš
	 */
	public class DrawUtils {
		/**
		 * Static method for joining several GraphicsPath objects into one
		 * @param	... paths	Array of GraphicsPath instances to be joined
		 * @return	new GraphicsPath instance which holds combination of data
		 */
		public static function joinGraphicPaths( ... paths):GraphicsPath {
			if (paths.length == 0) {
				return null;
			}
			var combined:GraphicsPath = new GraphicsPath();
			combined.commands = new Vector.<int>();
			combined.data = new Vector.<Number>();
			var path:GraphicsPath;
			for (var i:uint = 0; i < paths.length; i++) {
				path = paths[i] as GraphicsPath;
				combined.commands = combined.commands.concat(path.commands);
				combined.data = combined.data.concat(path.data);
			}
			return combined;
		}
		/**
		 * Static method that moves GraphicsPath data for certain x and y distance
		 * @param	path	GraphicsPath instance thats should be modified
		 * @param	add		Point which keeps for how much GraphicsPath values should be shifted
		 * @return	GraphicsPath instance
		 */
		public static function moveGraphicPath(path:GraphicsPath, add:Point):GraphicsPath {
			for (var i:uint = 0; i < path.data.length; i++) {
				if (i % 2 == 0) {
					path.data[i] += add.x;
				} else {
					path.data[i] += add.y;
				}
			}
			return path;
		}
		
		public function pathToSVG(path:Path):XML {
			
		}
	}
}